package com.gxuwz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.gxuwz.dao.impl.BaseDaoImpl;
import com.gxuwz.dao.impl.UserDaoImpl;
import com.gxuwz.entity.SysUser;
import com.gxuwz.service.IUserService;

@Service("userService")
public class UserServiceImpl extends BaseServiceImpl<SysUser> implements IUserService{
	
	private UserDaoImpl userDao; 
	
    
    @Override
	public SysUser findByUserName(String username) {
		List<SysUser> list = userDao.list("from SysUser where user_name=?", username);
		if(list.size()>0){
			return list.get(0);
		}else{
			return null;
		}		
	}
	
	@Override
	public boolean findByUserNameAndUserPassword(String userName,String userPassword){
		boolean flag = false;
		List<SysUser> list = userDao.list("from SysUser where user_name=? and user_password = ?",  userName,userPassword);
		if(list.size()>0){
			flag = true;
		}
		return flag;
	}

	@Override
    @Autowired(required = true)
    @Qualifier("userDao")
	public void setBaseDao(BaseDaoImpl<SysUser> baseDao) {
        this.baseDao = baseDao;
        this.userDao = (UserDaoImpl) baseDao;
	}

	@Override
	public boolean updateById(SysUser user) {
		if(user==null){
			return false;
		}
		SysUser u = userDao.load(user.getId());
		u.setTelephone(user.getTelephone());
		u.setUserName(user.getUserName());
		u.setUserPassword(user.getUserPassword());
		u.setUser_role(user.getUser_role());
		userDao.update(u);
		
		return true;
	}

   
}
